package com.yxq.mdt.app.modules.goodsdetail.ui;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewTreeObserver;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.orhanobut.hawk.Hawk;
import com.yxq.mdt.app.BuildConfig;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.application.IntentHelper;
import com.yxq.mdt.app.base.BaseActivity;
import com.yxq.mdt.app.constant.RouteTable;
import com.yxq.mdt.app.constant.SPKey;
import com.yxq.mdt.app.glide.GlideHelper;
import com.yxq.mdt.app.model.ShareBean;
import com.yxq.mdt.app.modules.bottomsheet.GoodsAttrBottomSheetDialogFragment;
import com.yxq.mdt.app.modules.bottomsheet.ShareSheetDialog;
import com.yxq.mdt.app.modules.goodsdetail.bean.GoodsCommentBean;
import com.yxq.mdt.app.modules.goodsdetail.bean.GoodsDetailBean;
import com.yxq.mdt.app.modules.goodsdetail.model.GoodsModel;
import com.yxq.mdt.app.modules.goodsdetail.presenter.GoodsPresenter;
import com.yxq.mdt.app.modules.goodsdetail.presenter.IGoodsContract;
import com.yxq.mdt.app.modules.market.bean.MallGoodsBean;
import com.yxq.mdt.app.modules.market.ui.MainMallGoodsListAdapter;
import com.yxq.mdt.app.modules.order.bean.OrderSubmitGoodsBean;
import com.yxq.mdt.app.modules.order.ui.OrderConfirmActivity;
import com.yxq.mdt.app.modules.personal.ui.activity.MainPersonalCustomerServiceAc;
import com.yxq.mdt.app.modules.picturebrowse.ui.PictureActivity;
import com.yxq.mdt.app.modules.shoppingcart.ui.CartActivity;
import com.yxq.mdt.app.utils.DisplayUtil;
import com.yxq.mdt.app.utils.GridSpacingItemDecoration;
import com.yxq.mdt.app.utils.StringUtils;
import com.yxq.mdt.app.widgets.pagemenulibrary.holder.ScreenUtil;
import com.yxq.mdt.app.widgets.tagview.TagView;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.CommonPagerTitleView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 商品详情 垂直下滑UI
 */
@Route(path = RouteTable.ROUTER_ACTIVITY_GOODS_DETAIL)
public class GoodsDetailTabVerticalActivity extends BaseActivity<GoodsPresenter> implements IGoodsContract.View {

    @Autowired
    String id = "";
    @BindView(R.id.magic_indicator)
    MagicIndicator magicIndicator;
    @BindView(R.id.top_layout)
    LinearLayout topLayout;
    @BindView(R.id.nested_scroll_view)
    NestedScrollView nestedScrollView;
    @BindView(R.id.gradient_line)
    View gradientLine;
    @BindView(R.id.goods_detail_layout_kf)
    LinearLayout goodsDetailLayoutKf;
    @BindView(R.id.goods_detail_iv_collect)
    ImageView goodsDetailIvCollect;
    @BindView(R.id.goods_detail_layout_collect)
    LinearLayout goodsDetailLayoutCollect;
    @BindView(R.id.goods_detail_layout_cart)
    LinearLayout goodsDetailLayoutCart;
    @BindView(R.id.goods_detail_tv_add_cart)
    TextView goodsDetailTvAddCart;
    @BindView(R.id.goods_detail_tv_buy)
    TextView goodsDetailTvBuy;
    @BindView(R.id.goods_detail_tab_bottom_layout)
    LinearLayout goodsDetailTabBottomLayout;
    String[] tabsArrays = new String[]{"商品", "评价", "详情"};
    @BindView(R.id.goods_img_banner)
    ConvenientBanner goodsImgBanner;
    @BindView(R.id.goods_tv_price)
    TextView goodsTvPrice;
    @BindView(R.id.goods_tv_sale_count)
    TextView goodsTvSaleCount;
    @BindView(R.id.goods_detail_tags)
    TagView goodsDetailTags;
    @BindView(R.id.goods_detail_tv_goods_name)
    TextView goodsDetailTvGoodsName;
    @BindView(R.id.goods_detail_tv_goods_label)
    TextView goodsDetailTvGoodsLabel;
    GoodsDetailBean mGoodsDetailBean;
    @BindView(R.id.goods_detail_tv_service)
    TextView goodsDetailTvService;
    @BindView(R.id.goods_detail_tv_recommend_count)
    TextView goodsDetailTvRecommendCount;
    @BindView(R.id.goods_detail_tv_recommend_more)
    TextView goodsDetailTvRecommendMore;
    @BindView(R.id.goods_detail_recycler_view_commend)
    RecyclerView goodsDetailRecyclerViewCommend;
    @BindView(R.id.goods_detail_tv_recommend)
    TextView goodsDetailTvRecommend;
    @BindView(R.id.goods_detail_recycler_view_recommend)
    RecyclerView goodsDetailRecyclerViewRecommend;
    GoodsCommentListAdapter goodsCommentListAdapter;
    List<GoodsCommentBean.ListBean> listBeanList;
    @BindView(R.id.goods_detail_web_view)
    WebView goodsDetailWebView;
    WebSettings webSettings;
    @BindView(R.id.goods_detail_line)
    View goodsDetailLine;
    @BindView(R.id.goods_detail_goods)
    RelativeLayout goodsDetailGoods;
    @BindView(R.id.goods_layout_web)
    LinearLayout goodsLayoutWeb;
    int commentLayoutHeightStartY = 0;
    int webViewLayoutHeightStartY = 0;
    GoodsAttrBottomSheetDialogFragment goodsAttrBottomSheetDialogFragment;

    @Override
    public int getLayoutId() {
        setEnableImmersion(true);
        setStatusBarColor(R.color.white);
        setStatusBarDarkFont(true);
        return R.layout.activity_goods_detail_tab_vertical;
    }

    @Override
    public void initView() {
        //顶部状态栏背景透明度
        nestedScrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                int mHeight = topLayout.getHeight();//获取标题栏高度
                if (scrollY <= 0) {//未滑动
                    topLayout.setVisibility(View.GONE);
                    topLayout.setBackgroundColor(Color.argb((int) 0, 255, 255, 255));
                } else if (scrollY > 0 && scrollY <= mHeight) { //滑动过程中 并且在mHeight之内
                    topLayout.setVisibility(View.VISIBLE);
                    float scale = (float) scrollY / mHeight;
                    float alpha = (255 * scale);
//                    topLayout.setTextColor(Color.argb((int) alpha, 255, 255, 255));
                    topLayout.setBackgroundColor(Color.argb((int) alpha, 255, 255, 255));
                } else {//超过mHeight
                    topLayout.setVisibility(View.VISIBLE);
                    topLayout.setBackgroundColor(Color.argb((int) 255, 255, 255, 255));
                }

                if (scrollY < commentLayoutHeightStartY) {
                    magicIndicator.onPageSelected(0);
                } else if (scrollY >= commentLayoutHeightStartY && scrollY < webViewLayoutHeightStartY) {
                    magicIndicator.onPageSelected(1);
                } else {
                    magicIndicator.onPageSelected(2);
                }
            }
        });
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        ARouter.getInstance().inject(this);
        mPresenter = new GoodsPresenter(this, new GoodsModel());

        int screenWidth = DisplayUtil.getScreenRelatedInformation(GoodsDetailTabVerticalActivity.this);
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, screenWidth);
        goodsImgBanner.setLayoutParams(layoutParams);
        goodsImgBanner.setPageIndicator(new int[]{R.drawable.shape_banner_selector_unchecked, R.drawable.shape_banner_selector_checked});

        goodsCommentListAdapter = new GoodsCommentListAdapter(R.layout.layout_goods_detail_comment_item_layout, listBeanList);
        goodsDetailRecyclerViewCommend.setLayoutManager(new LinearLayoutManager(GoodsDetailTabVerticalActivity.this));
        goodsDetailRecyclerViewCommend.setAdapter(goodsCommentListAdapter);
        goodsCommentListAdapter.setEmptyView(R.layout.layout_empty_view, goodsDetailRecyclerViewCommend);
        goodsCommentListAdapter.isUseEmpty(false);

        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setAdapter(new CommonNavigatorAdapter() {

            @Override
            public int getCount() {
                return tabsArrays.length;
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {
                CommonPagerTitleView commonPagerTitleView = new CommonPagerTitleView(GoodsDetailTabVerticalActivity.this);
                commonPagerTitleView.setContentView(R.layout.layout_nearby_item_layout);
                final TextView titleTitle = commonPagerTitleView.findViewById(R.id.indicator_tv_title);
                final ImageView sub = commonPagerTitleView.findViewById(R.id.indicator_tv_sub);
                titleTitle.setText(tabsArrays[index]);
                sub.setVisibility(View.GONE);
                commonPagerTitleView.setOnPagerTitleChangeListener(new CommonPagerTitleView.OnPagerTitleChangeListener() {

                    @Override
                    public void onSelected(int index, int totalCount) {
                        titleTitle.setTextSize(18);
                        titleTitle.setTextColor(getResources().getColor(R.color.color_font_black));
                    }

                    @Override
                    public void onDeselected(int index, int totalCount) {
                        titleTitle.setTextSize(15);
                        titleTitle.setTextColor(getResources().getColor(R.color.color_font_black));
                    }

                    @Override
                    public void onLeave(int index, int totalCount, float leavePercent, boolean leftToRight) {

                    }

                    @Override
                    public void onEnter(int index, int totalCount, float enterPercent, boolean leftToRight) {

                    }
                });
                commonPagerTitleView.setOnClickListener(v -> {
                    magicIndicator.onPageSelected(index);
                    switch (index) {
                        case 0:
                            nestedScrollView.scrollTo(0, 0);
                            break;
                        case 1:
                            nestedScrollView.scrollTo(0, commentLayoutHeightStartY);
                            break;
                        case 2:
                            nestedScrollView.scrollTo(0, webViewLayoutHeightStartY);
                            break;
                        default:
                    }
                });


                return commonPagerTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                return null;
            }
        });
        magicIndicator.setNavigator(commonNavigator);

        initWebView();

        mPresenter.getGoods(getIntent().getStringExtra("id"));
        mPresenter.getGoodsRecommend(getIntent().getStringExtra("id"));
        mPresenter.getCommentList(getIntent().getStringExtra("id"), 1);
    }

    @Override
    public void onLoadSuccess(GoodsDetailBean goodsDetailBean) {
        if (goodsDetailBean == null) {
            return;
        }
        mGoodsDetailBean = goodsDetailBean;
        initGoodsImages(goodsDetailBean);
        initGoodsInfo(goodsDetailBean);
        bindWebView(goodsDetailBean);
    }

    private void initWebView() {
        webSettings = goodsDetailWebView.getSettings();
        //启用JavaScript
        webSettings.setJavaScriptEnabled(true);
        //允许缩放
        webSettings.setSupportZoom(true);
        //不使用缓存
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
        //扩大比例的缩放
        webSettings.setUseWideViewPort(true);
        //自适应屏幕
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setLoadWithOverviewMode(true);
        goodsDetailWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }
        });
    }

    /**
     * 初始化商品详情webview
     *
     * @param goodsDetailBean
     */
    private void bindWebView(GoodsDetailBean goodsDetailBean) {
        goodsLayoutWeb.removeAllViews();
        goodsDetailWebView = new WebView(this);
        initWebView();
        if (goodsDetailBean != null && !TextUtils.isEmpty(goodsDetailBean.getDetail())) {
            goodsDetailWebView.loadDataWithBaseURL("", StringUtils.getNewData(goodsDetailBean.getDetail()), "text/html", "UTF-8", null);

            goodsLayoutWeb.addView(goodsDetailWebView, 0, new RelativeLayout.LayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)));
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    ViewTreeObserver vto = goodsLayoutWeb.getViewTreeObserver();
                    vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            /* 获取子控件信息 */
                            webViewLayoutHeightStartY = (goodsLayoutWeb.getTop() - 160);
                            /* 获取子控件信息后，注销回调用接口 */
                            goodsLayoutWeb.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                        }
                    });
                }
            }, 500);
        }
    }

    /**
     * 初始化商品文字介绍信息
     *
     * @param goodsDetailBean
     */
    private void initGoodsInfo(GoodsDetailBean goodsDetailBean) {
        goodsDetailTvGoodsName.setText(goodsDetailBean.getName());
        goodsTvPrice.setText(String.format("￥%.2f", goodsDetailBean.getPrice()));
        goodsTvSaleCount.setText(String.format("销量:%s", goodsDetailBean.getSales_volume()));
        if (goodsDetailBean.getService_list() != null) {
            goodsDetailTvGoodsLabel.setText(goodsDetailBean.getService_list().size() > 0 ? goodsDetailBean.getService_list().toString() : "");
        }
        goodsDetailIvCollect.setImageResource(goodsDetailBean.getIs_favorite() == 1 ? R.mipmap.ic_collect_checked : R.mipmap.ic_collect);
        //评价布局的起始高度坐标
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                ViewTreeObserver vto = goodsDetailTvRecommendCount.getViewTreeObserver();
                vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        /* 获取子控件信息 */
                        commentLayoutHeightStartY = (goodsDetailTvRecommendCount.getTop() - 150);
                        /* 获取子控件信息后，注销回调用接口 */
                        goodsDetailTvRecommendCount.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    }
                });
            }
        }, 500);
    }

    /**
     * 初始化商品滚动图片
     *
     * @param goodsDetailBean
     */
    private void initGoodsImages(GoodsDetailBean goodsDetailBean) {
        if (goodsDetailBean == null) {
            return;
        }
        if (goodsDetailBean.getPic_list() == null) {
            return;
        }
        goodsImgBanner.setPages(new CBViewHolderCreator() {
            @Override
            public Holder createHolder(View itemView) {

                return new ImageHolderView(itemView);
            }

            @Override
            public int getLayoutId() {
                return R.layout.layout_banner_item;
            }
        }, goodsDetailBean.getPic_list());
        goodsImgBanner.startTurning();
        goodsImgBanner.setOnItemClickListener(position -> {
            //预览
            Intent intent = new Intent(GoodsDetailTabVerticalActivity.this, PictureActivity.class);
            intent.putExtra("position", position);
            ArrayList<String> images = new ArrayList<>();
            for (GoodsDetailBean.PicListBean photoImgFile : goodsDetailBean.getPic_list()) {
                images.add(photoImgFile.getPic_url());
            }
            intent.putExtra("images", images);
            startActivity(intent);
        });
    }

    @Override
    public void onLoadFailed(String err) {
        ToastUtils.showShort(err);
    }

    @Override
    public void onLoadRecommendSuccess(MallGoodsBean mallGoodsBean) {
        //推荐商品
        if (mallGoodsBean.getList().size() == 0) {
            goodsDetailTvRecommend.setVisibility(View.GONE);
            return;
        }
        MainMallGoodsListAdapter mainMallGoodsListAdapter = new MainMallGoodsListAdapter(R.layout.layout_item_goods_list_ver_layout, mallGoodsBean.getList());
        mainMallGoodsListAdapter.setRow(3);
        goodsDetailRecyclerViewRecommend.setLayoutManager(new GridLayoutManager(GoodsDetailTabVerticalActivity.this, 3));
        goodsDetailRecyclerViewRecommend.setAdapter(mainMallGoodsListAdapter);
        mainMallGoodsListAdapter.setOnItemClickListener((adapter, view, position) -> {
            //跳转商品详情
            Bundle bundle = new Bundle();
            bundle.putString("id", mainMallGoodsListAdapter.getData().get(position).getId() + "");
            IntentHelper.arouter(RouteTable.ROUTER_ACTIVITY_GOODS_DETAIL, bundle);
        });
        if (goodsDetailRecyclerViewRecommend.getItemDecorationCount() == 0) {
            goodsDetailRecyclerViewRecommend.addItemDecoration(new GridSpacingItemDecoration(3, 8, false));
        }
    }

    @Override
    public void onLoadRecommendFailed(String err) {

    }

    @Override
    public void onAddSuccess(String err) {
        ToastUtils.showShort("收藏成功");
        if (getGoodsDetailBean() != null) {
            getGoodsDetailBean().setIs_favorite(1);
            goodsDetailIvCollect.setImageResource(R.mipmap.ic_collect_checked);
        }
    }

    @Override
    public void onAddFailed(String err) {
        ToastUtils.showShort(err);
    }

    @Override
    public void onRemoveSuccess(String err) {
        ToastUtils.showShort("取消收藏成功");
        if (getGoodsDetailBean() != null) {
            getGoodsDetailBean().setIs_favorite(0);
            goodsDetailIvCollect.setImageResource(R.mipmap.ic_collect);
        }
    }

    @Override
    public void onRemoveFailed(String err) {
        ToastUtils.showShort(err);
    }

    @Override
    public void onLoadCommentSuccess(GoodsCommentBean goodsCommentBean) {
        if (goodsCommentBean == null) {
            return;
        }
        if (goodsCommentBean.getList() == null) {
            return;
        }
        bindUI(goodsCommentBean);
        List<GoodsCommentBean.ListBean> commentBeanList = new ArrayList<>();

        for (int i = 0; i < goodsCommentBean.getList().size(); i++) {
            commentBeanList.add(goodsCommentBean.getList().get(i));
            if (i == 1) {
                break;
            }
        }
        goodsCommentListAdapter.setNewData(commentBeanList);
        goodsCommentListAdapter.isUseEmpty(!(goodsCommentListAdapter.getData().size() > 0));
    }

    private void bindUI(GoodsCommentBean goodsCommentBean) {
        goodsDetailTvRecommendCount.setText(String.format("商品评价(%d)", (goodsCommentBean.getPage_count() * goodsCommentBean.getRow_count())));
    }

    @Override
    public void onLoadCommentFailed(String err) {
        ToastUtils.showShort(err);
    }

    @Override
    public void onAddCartSuccess(String result) {
        ToastUtils.showShort(result);
    }

    @Override
    public void onAddCartFailed(String err) {
        ToastUtils.showShort(err);
    }

    ImageView collectStatus;

    public void add(ImageView collectStatus) {
        this.collectStatus = collectStatus;
        if (getGoodsDetailBean() != null) {
            if (getGoodsDetailBean().getIs_favorite() == 1) {
                mPresenter.favoriteRemove(getIntent().getStringExtra("id"));
            } else {
                mPresenter.favoriteAdd(getIntent().getStringExtra("id"));
            }
        }

    }

    /**
     * 返回商品详情
     *
     * @return
     */
    public GoodsDetailBean getGoodsDetailBean() {
        return mGoodsDetailBean;
    }

    @OnClick({R.id.goods_detail_layout_share, R.id.goods_detail_layout_kf, R.id.goods_detail_layout_collect, R.id.goods_detail_layout_cart, R.id.goods_detail_tv_add_cart, R.id.goods_detail_tv_buy, R.id.goods_detail_tv_recommend_more, R.id.goods_detail_ic_back})
    public void onClicked(View view) {
        switch (view.getId()) {
            case R.id.goods_detail_layout_kf://客服
                Intent intent = new Intent(mActivity, MainPersonalCustomerServiceAc.class);
                startActivity(intent);
                break;
            case R.id.goods_detail_layout_collect://收藏
                if (mGoodsDetailBean != null) {
                    if (mGoodsDetailBean.getIs_favorite() == 1) {
                        mPresenter.favoriteRemove(getIntent().getStringExtra("id"));
                    } else {
                        mPresenter.favoriteAdd(getIntent().getStringExtra("id"));
                    }
                }
                break;
            case R.id.goods_detail_layout_cart://购物车
                intent = new Intent(mActivity, CartActivity.class);
                startActivity(intent);
                break;
            case R.id.goods_detail_tv_add_cart://添加购物车
                boolean enable = Hawk.get(SPKey.SP_KEY_USER_LOGIN_PRIVACY, false);
                if (enable) {
                    ToastUtils.showShort("当前隐私模式，不可以添加购物车");
                    return;
                }
                if (mGoodsDetailBean != null) {
                    goodsAttrBottomSheetDialogFragment = new GoodsAttrBottomSheetDialogFragment(mGoodsDetailBean);
                    goodsAttrBottomSheetDialogFragment.setBottomSheetDialogInterface((attrBean, attr, num) -> addCart(attr, num));
                    goodsAttrBottomSheetDialogFragment.show(getSupportFragmentManager(), "GoodsAttrBottomSheetDialogFragment");
                }
                break;
            case R.id.goods_detail_tv_buy://立即购买
                enable = Hawk.get(SPKey.SP_KEY_USER_LOGIN_PRIVACY, false);
                if (enable) {
                    ToastUtils.showShort("当前隐私模式，不可以购买");
                    return;
                }
                //判断是否有多个规格，多个规格需要弹出框选择规格
                if (mGoodsDetailBean != null) {
                    goodsAttrBottomSheetDialogFragment = new GoodsAttrBottomSheetDialogFragment(mGoodsDetailBean);
                    goodsAttrBottomSheetDialogFragment.setBottomSheetDialogInterface((attrBean, attr, num) -> {
                        //构造规格
                        GoodsDetailBean data = JSON.parseObject(JSON.toJSONString(mGoodsDetailBean), GoodsDetailBean.class);
                        List<GoodsDetailBean.AttrBean> attrBeanList = data.getAttr();
                        attrBeanList.set(0, attrBean);
                        data.setAttr(attrBeanList);
                        data.setNum(num);
                        if(attrBean.getPrice()!=0){
                            data.setPrice(attrBean.getPrice());
                        }

                        Intent intent1 = new Intent(mActivity, OrderConfirmActivity.class);
                        intent1.putExtra("from", "goods");
                        intent1.putExtra("attr", attr);
                        intent1.putExtra("data", JSON.toJSONString(data));
                        startActivity(intent1);
                    });
                    goodsAttrBottomSheetDialogFragment.show(getSupportFragmentManager(), "GoodsAttrBottomSheetDialogFragment");
                }
                break;
            case R.id.goods_detail_tv_recommend_more:
                //更多评价
                Intent intentAc = new Intent(mActivity, GoodsDetailCommentActivity.class);
                intentAc.putExtra("id", getIntent().getStringExtra("id"));
                startActivity(intentAc);
                break;
            case R.id.goods_detail_ic_back:
                finish();
                break;
            case R.id.goods_detail_layout_share:
                if (mGoodsDetailBean == null) {
                    return;
                }
                //分享
                ShareBean shareBean = new ShareBean();
                shareBean.setTitle(mGoodsDetailBean.getName() + " ￥" + mGoodsDetailBean.getPrice());//标题
                shareBean.setText(mGoodsDetailBean.getService_list().toString());//文本
                shareBean.setShareType("0");//图文分享
                shareBean.setShareTypeAPP(3);
                shareBean.setHandleId(mGoodsDetailBean.getId() + "");
                //http://192.168.110.61/webgoods.html?goodsId=263&platform=2&parent_id=13612345678
                if ((mGoodsDetailBean.getPic_list().size()) > 0) {
                    shareBean.setImageUrl(mGoodsDetailBean.getPic_list().get(0).getPic_url());//LOGO
                } else {
                    shareBean.setImageUrl("https://yxqoss.oss-cn-hangzhou.aliyuncs.com/gs_app/init/727c432c9e186a11.png");//LOGO
                }
                if (!"release".equals(BuildConfig.RELEASE)) {
                    shareBean.setUrl("http://testpm.quai69.com/webgoods.html?goodsId=" + mGoodsDetailBean.getId() + "&platform=2&parent_id=" + getParentId());//分享URL
                } else {
                    shareBean.setUrl("http://pm.quai69.com/webgoods.html?goodsId=" + mGoodsDetailBean.getId() + "&platform=2&parent_id=" + getParentId());
                }
                ShareSheetDialog shareSheetDialog = new ShareSheetDialog(shareBean, false);
                shareSheetDialog.show(getSupportFragmentManager(), "shareSheetDialog");
                break;
        }
    }

    /**
     * 添加购物车
     *
     * @param attr 规格
     * @param num  数量
     */
    private void addCart(String attr, int num) {
        mPresenter.addCart(getIntent().getStringExtra("id"), num, attr);
    }

    /**
     * 图片轮转实现
     */
    class ImageHolderView extends Holder<GoodsDetailBean.PicListBean> {
        private ImageView imageView;

        public ImageHolderView(View itemView) {
            super(itemView);
        }

        @Override
        protected void initView(View itemView) {
            imageView = itemView.findViewById(R.id.banner_image);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        }

        @Override
        public void updateUI(GoodsDetailBean.PicListBean bean) {
            GlideHelper.setLoadImage(GoodsDetailTabVerticalActivity.this, bean.getPic_url(), R.color.gray, imageView);
        }
    }

}
